<template>
  <component
    :is="btnComponent.component"
    class="btn-secondary"
    :class="[
      { 'btn-secondary-w-100': fillWidth },
      { 'btn-secondary--white': white },
      { 'btn-secondary--light': light },
    ]"
    v-bind:[btnComponent.href]="url"
    v-bind:[btnComponent.to]="isNuxtLink ? url : undefined"
    v-bind:[btnComponent.type]="typeForBtn"
    v-bind:[btnComponent.target]="'_blank'"
    v-on="btnAction"
  >
    <div class="btn-secondary-text">{{ text }}</div>
  </component>
</template>

<script lang="ts" setup>
import { computed } from 'vue'

defineOptions({
  name: 'BtnSecondary'
})

interface BtnComponent {
  component: string
  href: string | null
  to: string | null
  type: string | null
  target: string | null
}

interface Props {
  text?: string
  url?: string
  buttonType?: 'button' | 'outer-link' | 'nuxt-link'
  white?: boolean
  light?: boolean
  fillWidth?: boolean
  typeForBtn?: string
  action?: string
  actionKey?: string
}

const props = withDefaults(defineProps<Props>(), {
  text: 'Button',
  url: '#',
  buttonType: 'button',
  white: false,
  light: false,
  fillWidth: false,
  typeForBtn: 'button',
  action: '',
  actionKey: ''
})

const emit = defineEmits(['showLightboxDonation'])

const btnComponent = computed<BtnComponent>(() => {
  switch (props.buttonType) {
    case 'outer-link':
      return {
        component: 'a',
        href: 'href',
        to: null,
        type: null,
        target: 'target'
      }
    case 'nuxt-link':
      return {
        component: 'nuxt-link',
        href: null,
        to: 'to',
        type: null,
        target: null
      }
    default:
      return {
        component: 'button',
        href: null,
        to: null,
        type: 'type',
        target: null
      }
  }
})

const btnAction = computed(() => {
  switch (props.action) {
    case 'donate':
      return { click: actionShowLightboxDonation }
    default:
      return null
  }
})

const isNuxtLink = computed(() => props.buttonType === 'nuxt-link')

function actionShowLightboxDonation() {
  emit('showLightboxDonation', { key: props.actionKey })
}
</script>

<style lang="scss" scoped>
.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--text-color--primary, #0032a0);
  padding: 6px;
  min-width: 100px;
  border: none;
  border-radius: 2px;
  overflow: hidden;
  text-decoration: none;
  position: relative;
  z-index: 1;

  @media (max-width: 767.98px) {
    padding: 6px;
    min-width: 150px;
  }
}

.btn-secondary::before {
  content: '';
  display: block;
  background: #0048e8;
  position: absolute;
  width: 200%;
  height: 500%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: all 0.3s ease-in-out;
  z-index: -1;
  clip-path: circle(100% at -80% 90%);
}

.btn-secondary:hover::before {
  clip-path: circle(100% at 50% 50%);
}

.btn-secondary:active::before {
  clip-path: circle(100% at -80% 90%);
}

.btn-secondary-text {
  font-size: 16px;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: 0.01em;
  color: #ffffff;
  transition: color 0.3s ease-in-out;

  @media (max-width: 1023.98px) {
    font-size: 16px;
    line-height: 1.25;
    letter-spacing: 0.01em;
  }
}

.btn-secondary--light {
  background-color: #e8f4f8;
}

.btn-secondary--light .btn-secondary-text {
  color: #004d7a;
}

.btn-secondary--light::before {
  background: #00a8cc;
}

.btn-secondary--light:hover .btn-secondary-text {
  color: #0032a0;
}

.btn-secondary--light:active .btn-secondary-text {
  color: #004d7a;
}

.btn-secondary--white {
  background-color: transparent;
  border: 1px solid #f7f7fa;
}

.btn-secondary--white .btn-secondary-text {
  color: #ffffff;
}

.btn-secondary--white::before {
  background: none;
}

.btn-secondary--white:hover {
  opacity: 0.7;
}

.btn-secondary--white:active {
  opacity: 1;
}

.btn-secondary-w-100 {
  width: 100%;
}
</style>